<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\model;

/**
 * 工单模型
 */
class ChannelWorkContent extends ModelBase
{
    protected $insert = ['create_time'];

    public function getImageAttr(){
        return get_picture_url($this->cover_id,false);
    }


    /**
     * 连分类表
     */
    public function cate(){
        return $this->belongsTo('ChannelWorkClass','class','id');
    }

    /**
     * 连用户表
     */
    public function user(){
        return $this->belongsTo('Member','user_id','id');
    }
    /**
     * 获取状态信息
     */
    public function getStateTextAttr(){
        $arr=['','待处理','已处理','已反馈','已完结','已好评'];
        return lang($arr[$this->state]);
    }

    /**
     * 获取工单处理耗时
     */
    public function getDealTimeAttr(){
        $senconds = strtotime($this->update_time)-strtotime($this->create_time);
        return gmdate("H:i:s",$senconds);
    }

    /**
     * 连回复表
     */
    public function reply(){
        return $this->hasMany('ChannelWorkComment','wid','id');
    }

    /**
     * 时间获取器
     */
    public function getCreateTimeAttr($value)
    {

        return date('Y-m-d H:i:s',$value);
    }

    public function getUpdateTimeAttr($value)
    {

        return date('Y-m-d H:i:s',$value);
    }

    /**
     * 时间自动完成
     */
    public function setCreateTimeAttr()
    {

        return TIME_NOW;
    }
  
//  public function  getCateNameAttr(){
//      $lang=isset($_REQUEST['lang'])?$_REQUEST['lang']:'';
//      return   baidu_translate($this->cate['name'],$lang);
//
//
//    }

//    public function  getDescribeAttr($value){
//
//        $lang=isset($_REQUEST['lang'])?$_REQUEST['lang']:'';
//        return   baidu_translate($value,$lang);
//
//
//    }

//    public function  getContentAttr($value){
//        $lang=isset($_REQUEST['lang'])?$_REQUEST['lang']:'';
//        return   baidu_translate($value,$lang);
//
//    }
}
